﻿@model EasyHome.Models.Contacto

@{
    ViewBag.Title = "Edit";
}

<h2>Edit</h2>


@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>Contacto</h4>
        <hr />
        @Html.ValidationSummary(true)
        @Html.HiddenFor(model => model.Id)

        <div class="form-group">
            @Html.LabelFor(model => model.Nombre, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.TextBoxFor(model => model.Nombre, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Nombre)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Apellido, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.TextBoxFor(model => model.Apellido, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Apellido)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.FechaDeNacimiento, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.TextBoxFor(model => model.FechaDeNacimiento, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.FechaDeNacimiento)
            </div>
        </div>

        <div class="panel panel-default">
            <!-- Default panel contents -->
            <div class="panel-heading">
                Datos del contacto
                @Html.ActionLink("Create New", "Create", "ContactoDato", new { @class = "btn btn-primary btn-xs pull-right" })
            </div>

            <!-- Table -->
            <table class="table">
                <tr>
                    <th>
                        Tipo
                    </th>
                    <th>
                        Dato
                    </th>
                    <th></th>
                </tr>
                @foreach (var item in Model.Datos)
                {
                    <tr>
                        <td>
                            @Html.DisplayFor(modelItem => item.TablaDato.Descripcion)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.Dato)
                        </td>
                        <td>
                            
                            @Html.ActionLink("Add Service", "Create", null, null, new { @class = "btnEdit btn btn-small btn-info" })
                            
                            @Html.ActionLink("Edit", EasyHome.Controllers.ContactoDatoController.  .Edit(item.id), new { @class = "btnEdit btn btn-small btn-info" })
                            @Html.ActionLink(" ", "Details", new { id = item.id }, new { @class = "glyphicon glyphicon-search" })
                            @Html.ActionLink(" ", "Delete", new { id = item.id }, new { @class = "glyphicon glyphicon-trash" })
                        </td>
                    </tr>
                }
            </table>
        </div>




        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Save" class="btn btn-default" />
            </div>
        </div>
    </div>

    <div id='dialogDiv' class='modal hide fade in'>
        <div id='dialogContent'></div>
    </div>


    @section scripts
{
        <script type="text/javascript">

            $(function () {

                $.ajaxSetup({ cache: false });

                $('.btnEdit').click(function () {
                    $('#dialogContent').load(this.href, function () {
                        $('#dialogDiv').modal({
                            backdrop: 'static',
                            keyboard: true
                        }, 'show');
                        bindForm(this);

                    });
                    return false;
                });
            });

            function bindForm(dialog) {
                $('form', dialog).submit(function () {
                    $.ajax({
                        url: this.action,
                        type: this.method,
                        data: $(this).serialize(),
                        success: function (result) {
                            if (result.success) {
                                $('#dialogDiv').modal('hide');
                                location.reload();
                            } else {
                                $('#dialogContent').html(result);
                                bindForm();
                            }
                        }
                    });
                    return false;
                });
            }
        </script>
    }

}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}
